//
// Created by htlin on 2021/3/2 0002.
//

#ifndef LIBUVTEST_RUNNABLE_H
#define LIBUVTEST_RUNNABLE_H

#include "header.h"

class RunnablePrivateData;

class Runnable {
public:
    typedef void (*FinishedCallBack)(uv_work_t* request, void *data);

public:
    explicit Runnable();

    virtual ~Runnable();

    void setAutoDelete(bool autoDelete);

    bool getAutoDelete() const;

    void setFinishedCallBack(FinishedCallBack finishCallBack, void* userData);

protected:
    virtual void run();

    virtual void finish(bool isCancel);

public:
    static void runCB(uv_work_t *data);

    static void finishCB(uv_work_t *data, int status);

private:
    std::unique_ptr<RunnablePrivateData> data;

    friend class ThreadPool;
};


#endif //LIBUVTEST_RUNNABLE_H
